package com.hutianao.gqgl.dictionary.control;

import com.hutianao.gqgl.dictionary.service.DictionaryService;
import com.hutianao.gqgl.mybatis.entity.PtDictionaryEntity;
import com.hutianao.gqgl.mybatis.entity.PtDictionaryI18n;
import com.hutianao.gqgl.mybatis.entity.PtMenuEntity;
import com.hutianao.gqgl.mybatis.entity.PtMenuI18n;
import com.hutianao.gqgl.mybatis.ztree.ZtreeEntity;
import com.hutianao.gqgl.spring.control.BaseController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;


@Controller
@RequestMapping("/dictionary")
public class DictionaryController extends BaseController{
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private DictionaryService dictionaryService;

    @RequestMapping("/dictionaryPage")
    public String dictionaryPage(){
        return "dictionary/dictionaryPage";

    }
    @RequestMapping("/queryLeftTree")
    @ResponseBody
    public List<ZtreeEntity> queryLeftTree(){
        return dictionaryService.queryLeftTree();
    }

    @RequestMapping("/queryDictionaryListById")
    @ResponseBody
    public PtDictionaryEntity queryDictionaryListById(@RequestParam("dictionaryId") String dictionaryId){
        logger.info("dictionaryId:" + dictionaryId);
        PtDictionaryEntity ptDictionaryEntity = dictionaryService.querydictionaryListById(dictionaryId);
        return ptDictionaryEntity;
    }

    @RequestMapping("/getI18nByDictionaryId")
    @ResponseBody
    public List<PtDictionaryI18n> getI18nByDictionaryId(@RequestParam("dictionaryId")String dictionaryId){
        logger.info("dictionaryId:" + dictionaryId );
        List<PtDictionaryI18n> list = dictionaryService.getI18nByDictionaryId(dictionaryId);
        return list;
    }
    @RequestMapping("/deleteDictionaryI18nById")
    @ResponseBody
    public String deleteDictionaryI18nById(@RequestParam("dictId")String dictId,@RequestParam("languageId")String languageId){
        logger.info("dictId:" + dictId + " languageId:" + languageId);

        dictionaryService.deleteDictionaryI18nById(dictId,languageId);
        return jsonSuccess("dictionary.delete.i18n.success");
    }
    @RequestMapping("/saveDictionaryI18n")
    @ResponseBody
    public String saveDictionaryI18n(PtDictionaryI18n ptDictionaryI18n){
        logger.info(ptDictionaryI18n);

        dictionaryService.saveDictionaryI18n(ptDictionaryI18n);
        return jsonSuccess("dictionary.save.i18n.success");
    }
    @RequestMapping("/addDictionaryInfo")
    @ResponseBody
    public String addDictionaryInfo(PtDictionaryEntity ptDictionaryEntity){
        logger.info("ptDictionaryEntity:" + ptDictionaryEntity );
        dictionaryService.addDictionaryInfo(ptDictionaryEntity);
        return jsonSuccess("dictionary.add.success");
    }

    @RequestMapping("/deleteDictionaryInfoByDictionaryId")
    @ResponseBody
    public String deleteDictionaryInfoByDictionaryId(@RequestParam("dictId")String dictId){
        logger.info("dictId:" + dictId );
        dictionaryService.deleteDictionaryInfoByDictionaryId(dictId);
        return  jsonSuccess("dictionary.delete.success");

    }
    //    shen
    @RequestMapping("/updateDictionaryInfo")
    @ResponseBody
    public String updateDictionaryInfo(PtDictionaryEntity ptDictionaryEntity){
        logger.info("ptDictionaryEntity:" + ptDictionaryEntity );
       dictionaryService.updateDictionaryInfo(ptDictionaryEntity);
        return jsonSuccess("dictionary.update.success");
    }
}
